﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace PrattParsing
{
    [DebuggerNonUserCode]
    public struct TokenMatch
    {
        public const bool TEXT = false, TYPE = true;

        public int type;
        public string text;
        public bool matchType;

        public TokenMatch(string text)
        {
            this.type = -1;
            this.text = text;
            this.matchType = TEXT;
        }
        public TokenMatch(int type)
        {
            this.type = type;
            this.text = "";
            this.matchType = TYPE;
        }

        public bool Matches(Token token)
        {
            return (matchType == TEXT) ? (text == token.text) : (type == token.type);
        }

        public override string ToString()
        {
            return (matchType == TEXT) ? ("\"" + text + "\"") : (Token.TYPE_NAMES[type]);
        }

        public static TokenMatch Text(string text)
        {
            return new TokenMatch(text);
        }
        public static TokenMatch Type(int type)
        {
            return new TokenMatch(type);
        }

        public static implicit operator TokenMatch(string text)
        {
            return new TokenMatch(text);
        }
        public static implicit operator TokenMatch(int type)
        {
            return new TokenMatch(type);
        }
    }
}
